﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Tools.Common.UnitOfWork.Contracts;
using Tools.Domain.Common.Repositories.Contracts;
using Tools.Domain.Specifications;
using Web.App.Infrastructure.Context.Contracts;
using Web.App.Infrastructure.UnitOfWork;
using Webshop20.Constants;
using Webshop20.Domain.Security.Authentication.Core;
using Webshop20.Domain.Security.Authentication.Factories.Contracts;


namespace Webshop20.Domain.Security.Authentication.Repositories.Implementation
{
    public class AccountRepository : IRepository<Account>
    {
        private readonly IAccountFactory accountFactory;
        private readonly ICustomSessionState sessionState;
        private readonly IUnitOfWork unitOfWork;

        public AccountRepository(IAccountFactory accountFactory, ICustomSessionState sessionState)
        {
            this.accountFactory = accountFactory;
            this.unitOfWork = unitOfWork;
            this.sessionState = sessionState;
        }

        #region IRepository<Account> Members

        public void Add(Account instance)
        {
            throw new NotImplementedException();
        }

        public void Save(Account instance)
        {
            throw new System.NotImplementedException();
        }

        public void Update(Account instance)
        {
            throw new NotImplementedException();
        }

        public void SaveOrUpdate(Account instance)
        {
            throw new System.NotImplementedException();
        }

        public void SaveOrUpdateCopy(Account instance)
        {
            throw new System.NotImplementedException();
        }

        public void Delete(Account instance)
        {
            throw new NotImplementedException();
        }

        public Account FindById(object id)
        {
            if (id == CONSTANTS.VALUES.GUEST_ACCOUNT_ID)
            {
                if (sessionState[CONSTANTS.KEYS.GUEST_ACCOUNT] == null)
                    sessionState[CONSTANTS.KEYS.GUEST_ACCOUNT] =
                        accountFactory.Create();

                return sessionState[CONSTANTS.KEYS.GUEST_ACCOUNT] as Account;
            }
            return UnitOfWork.AsSession.LoadById<Account>(id);
        }

        public IEnumerable<Account> FindAll()
        {
            throw new NotImplementedException();
        }

        public IQueryable<Account> Find(Expression<Func<Account, bool>> searchTerm)
        {
            throw new System.NotImplementedException();
        }

        public IQueryable<Account> Find(Func<Account, bool> searchTerm)
        {
            throw new System.NotImplementedException();
        }

        public IQueryable<Account> FindBySpecification(ISpecification<Account> specification)
        {
            throw new System.NotImplementedException();
        }

        public IQueryable<Account> FindByQuery(IQuery<Account> query)
        {
            throw new System.NotImplementedException();
        }

        public IQueryable<R> FindInRole<R>(Expression<Func<Account, bool>> searchTerm)
        {
            throw new System.NotImplementedException();
        }

        public R FindByIdInRole<R>(object id)
        {
            throw new System.NotImplementedException();
        }

        public IEnumerable<R> FindAllInRole<R>()
        {
            throw new System.NotImplementedException();
        }

        public IQueryable<R> FindBySpecificationInRole<R>(ISpecification<Account> specification)
        {
            throw new System.NotImplementedException();
        }

        public IFutureValue<Account> FutureFindById(object id)
        {
            throw new System.NotImplementedException();
        }

        public IFutureQueryOf<Account> FutureFindAll()
        {
            throw new System.NotImplementedException();
        }

        public IFutureQueryOf<Account> FutureFind(Expression<Func<Account, bool>> searchTerm)
        {
            throw new System.NotImplementedException();
        }

        public IFutureQueryOf<Account> FutureFindBySpecification(ISpecification<Account> specification)
        {
            throw new System.NotImplementedException();
        }

        #endregion
    }
}